package admin

import (
	"gin-base/base/resp"
	"gin-base/common/models/admin"
	"github.com/gin-gonic/gin"
)

type LoginForm struct {
	UserName string `form:"username" json:"username" binding:"required"`
	Password string `form:"password" json:"password" binding:"required"`
}

func Login(this *gin.Context) {
	var form LoginForm

	if this.BindJSON(&form) == nil {
		admin := admin.Login(form.UserName, form.Password)

		if admin == nil {
			resp.Error(this, "AUTH", "")
		}

		resp.Success(this, admin)
	}
}
